Ext.ns('Portal.menuObject');

Ext.apply(Portal.menuObject, {
    exec: function (config) {
        if (Ext.getCmp('menuObjects')) {
            //adaugare meniuri in componenta menuObjects aflata in regiunea nord ( butonul Operatii)
            var menu = Ext.getCmp('menuObjects');

            //add county
            var countyForm = new Ext.form.FormPanel({
                width: 400,
                height: 80,
                frame: true,
                labelWidth: 45,
                items: [
                    {
                        fieldLabel: 'Judet',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addCounty",
                        itemId: "county",
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {
                                table: "nomcounty"
                            },
                            proxyUrl: 'County/GetCounty/'                                 }
                    }
                ],
                buttons: [
                    {
                        text: 'Salveaza',
                        handler: function () {
                            var cbCounty = countyForm.find("itemId", "county")[0];
                            Ext.Ajax.request({
                                url: 'County/AddCounty/',
                                params: { data: cbCounty.getRawValue(), table: 'county' },
                                success: function (response) {
                                    cbCounty.reset();
                                }
                            });
                        }
                    }
                ]
            });

            //add city

            var cityForm = new Ext.form.FormPanel({
                width: 400, height: 110, frame: true, labelWidth: 70,
                items: [
                    {
                        fieldLabel: 'Judet',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addCounty",
                        itemId: "county",
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {},
                            proxyUrl: 'County/GetCounty/'
                        },
                        listeners: {
                            select:  function (combo, value) {
                                cbCity = cityForm.find("itemId", "city")[0];
                                cbCity.setValue('');
                                cbCity.setDisabled(false);
                                cbCity.store.load({ params : {
                                    county_id : combo.getValue()
                                }
                                });
                            }
                        } ,
                        getListParent: function () {
                            return this.el.up('.x-menu');
                        }
                    }
                    ,
                    {
                        fieldLabel: 'City',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addCity",
                        itemId: "city",
                        disabled : true,
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {},
                            proxyUrl: 'City/GetCity/'
                        }

                    }
                ],
                buttons: [
                    {
                        text: 'Salveaza',
                        handler: function () {
                            var city = cityForm.find("itemId", "city")[0].getRawValue();
                            var county = cityForm.find("itemId", "county")[0].getValue();
                            if ((city != '') && (county != '')) {
                                Ext.Ajax.request({
                                    url: 'City/AddCity/' ,
                                    params: { city: city,  county: county }
                                });
                            }
                            else {
                                console.log("Una din date este nula");
                                //Portal.events.throwWarning("Una din date este nula");
                            }
                        }
                    }
                ]
            });

            //departament
            var divisionForm = new Ext.form.FormPanel({
                width: 400,
                height: 80,
                frame: true,
                labelWidth: 70,
                items: [
                    {
                        fieldLabel: 'Departament',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addDept",
                        itemId: "dept",
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {},
                            proxyUrl: 'Division/GetDivision/'                                 }
                    }
                ],
                buttons: [
                    {
                        text: 'Salveaza',
                        handler: function () {
                            var cbDiv = divisionForm.find("itemId", "dept")[0];
                            Ext.Ajax.request({
                                url: 'Division/AddDivision/',
                                params: { data: cbDiv.getRawValue(), table: 'division' },
                                success: function (response) {
                                    cbDiv.reset();
                                }
                            });
                        }
                    }
                ]
            });

            //functie
            var positionForm = new Ext.form.FormPanel({
                width: 400,
                height: 80,
                frame: true,
                labelWidth: 70,
                items: [
                    {
                        fieldLabel: 'Functie',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addPosition",
                        itemId: "position",
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {},
                            proxyUrl: 'Position/GetPosition/'                                 }
                    }
                ],
                buttons: [
                    {
                        text: 'Salveaza',
                        handler: function () {
                            var cbDiv = positionForm.find("itemId", "position")[0];
                            Ext.Ajax.request({
                                url: 'Position/AddPosition/',
                                params: { data: cbDiv.getRawValue(), table: 'position' },
                                success: function (response) {
                                    cbDiv.reset();
                                }
                            });
                        }
                    }
                ]
            });

            //subfunctie

            var subPosForm = new Ext.form.FormPanel({
                width: 400, height: 110, frame: true, labelWidth: 70,
                items: [
                    {
                        fieldLabel: 'Functie',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addPosition",
                        itemId: "position",
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {},
                            proxyUrl: 'Position/GetPosition/'
                        },
                        listeners: {
                            select:  function (combo, value) {
                                cbSubPos = subPosForm.find("itemId", "subposition")[0];
                                cbSubPos.setValue('');
                                cbSubPos.setDisabled(false);
                                cbSubPos.store.load({ params : {
                                    position_id : combo.getValue()
                                }
                                });
                            }
                        } ,
                        getListParent: function () {
                            return this.el.up('.x-menu');
                        }
                    }
                    ,
                    {
                        fieldLabel: 'Subfunctie',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addSubposition",
                        itemId: "subposition",
                        disabled : true,
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {},
                            proxyUrl: 'Subposition/GetSubposition/'
                        }

                    }
                ],
                buttons: [
                    {
                        text: 'Salveaza',
                        handler: function () {
                            var subposition = subPosForm.find("itemId", "subposition")[0].getRawValue();
                            var position = subPosForm.find("itemId", "position")[0].getValue();
                            if ((subposition != '') && (position != '')) {
                                Ext.Ajax.request({
                                    url: 'Subposition/AddSubposition/' ,
                                    params: { subposition: subposition,  position: position }
                                });
                            }
                            else {
                                console.log("Una din date este nula");
                                //Portal.events.throwWarning("Una din date este nula");
                            }
                        }
                    }
                ]
            });

            //domeniu

            var domainForm = new Ext.form.FormPanel({
                width: 400,
                height: 80,
                frame: true,
                labelWidth: 45,
                items: [
                    {
                        fieldLabel: 'Domeniu',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addDomain",
                        itemId: "domain",
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {
                                table: "domains"
                            },
                            proxyUrl: 'Domain/GetDomain/'
                        }
                    }
                ],
                buttons: [
                    {
                        text: 'Salveaza',
                        handler: function () {
                            var cbDomain = domainForm.find("itemId", "domain")[0];
                            Ext.Ajax.request({
                                url: 'Domain/AddDomain/',
                                params: { data: cbDomain.getRawValue(), table: 'domains' },
                                success: function (response) {
                                    cbDomain.reset();
                                }
                            });
                        }
                    }
                ]
            });

            //subdomeniu
            var subDomainForm = new Ext.form.FormPanel({
                width: 400, height: 110, frame: true, labelWidth: 70,
                items: [
                    {
                        fieldLabel: 'Domeniu',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addDomain",
                        itemId: "domain",
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {
                                table: "domains"
                            },
                            proxyUrl: 'Domain/GetDomain/'
                        },
                        listeners: {
                            select:  function (combo, value) {
                                cbSubDomain = subDomainForm.find("itemId", "subdomain")[0];
                                cbSubDomain.setValue('');
                                cbSubDomain.setDisabled(false);
                                cbSubDomain.store.load({ params : {
                                    domain_id : combo.getValue()
                                }
                                });
                            }
                        } ,
                        getListParent: function () {
                            return this.el.up('.x-menu');
                        }
                    }
                    ,
                    {
                        fieldLabel: 'Subdomeniu',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addSubdomain",
                        itemId: "subdomain",
                        disabled : true,
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {},
                            proxyUrl: 'Subdomain/GetSubdomain/'
                        }

                    }
                ],
                buttons: [
                    {
                        text: 'Salveaza',
                        handler: function () {
                            var subdomain = subDomainForm.find("itemId", "subdomain")[0].getRawValue();
                            var domain = subDomainForm.find("itemId", "domain")[0].getValue();
                            if ((subdomain != '') && (domain != '')) {
                                Ext.Ajax.request({
                                    url: 'Subdomain/AddSubdomain/' ,
                                    params: { subdomain: subdomain,  domain: domain }
                                });
                            }
                            else {
                                console.log("Una din date este nula");
                                //Portal.events.throwWarning("Una din date este nula");
                            }
                        }
                    }
                ]
            });

            //campanie

            var campaignForm = new Ext.form.FormPanel({
                width: 400,
                height: 80,
                frame: true,
                labelWidth: 45,
                items: [
                    {
                        fieldLabel: 'Campanie',
                        xtype: "uxFCombo",
                        anchor: "70%",
                        name: "addCampaign",
                        itemId: "campaign",
                        forceSelection: false,
                        minChars: 2,
                        easyConfig: {
                            baseParams: {
                            },
                            proxyUrl: 'Campaign/GetCampaign/'
                        }
                    }
                ],
                buttons: [
                    {
                        text: 'Salveaza',
                        handler: function () {
                            var cbCampaign = campaignForm.find("itemId", "campaign")[0];
                            Ext.Ajax.request({
                                url: 'Campaign/AddCampaign/',
                                params: { data: cbCampaign.getRawValue(), table: 'campaign' },
                                success: function (response) {
                                    cbCampaign.reset();
                                }
                            });
                        }
                    }
                ]
            });

            ///////////////////////////////////////////////////
            var items = [
                {
                    iconCls: 'icon-attach',  // <-- icon
                    text: 'Adauga Judet',
                    menu: {
                        items: [countyForm]
                    }
                },
                {
                    iconCls: 'icon-attach',  // <-- icon
                    text: 'Adauga Oras',
                    menu: {
                        items: [cityForm]
                    }
                },
                {
                    iconCls: 'icon-attach',  // <-- icon
                    text: 'Adauga Departament',
                    menu: {
                        items: [divisionForm]
                    }
                },
                {
                    iconCls: 'icon-attach',  // <-- icon
                    text: 'Adauga Functie',
                    menu: {
                        items: [positionForm]
                    }
                },
                {
                    iconCls: 'icon-attach',  // <-- icon
                    text: 'Adauga Subfunctie',
                    menu: {
                        items: [subPosForm]
                    }
                },
                {
                    iconCls: 'icon-attach',  // <-- icon
                    text: 'Adauga Domeniu',
                    menu: {
                        items: [domainForm]
                    }
                },
                {
                    iconCls: 'icon-attach',  // <-- icon
                    text: 'Adauga SubDomeniu',
                    menu: {
                        items: [subDomainForm]
                    }
                },
                {
                    iconCls: 'icon-attach',  // <-- icon
                    text: 'Adauga Campanie',
                    menu: {
                        items: [campaignForm]
                    }
                }
            ];
            menu.add(items);
            menu.doLayout();
        }
    }
});